import { createApp } from 'vue'
//引入plus
import ElementPlus from 'element-plus'
import { createPinia } from 'pinia'
import 'element-plus/dist/index.css'
import {router} from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 导入 axios
import App from './App.vue'
const app = createApp(App)
const pinia = createPinia()

// 将 axios 挂载到全局

// 是否在启动时生成生产提示
app.config.productionTip = false
import axios from 'axios'

// 指定 axios 的全局配置，指定为后端服务器地址
axios.defaults.baseURL = 'http://localhost:8080/'
axios.defaults.withCredentials = true;
app.config.globalProperties.$urlImage = 'http://localhost:8080/images/';
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
axios.interceptors.request.use(config => {
    //从本地读取token
    const token = localStorage.getItem('token')
    //判断token是否存在
    if (token) {
        //将token添加到请求头中
        config.headers.Authorization = `Bearer ${token}`
    }
    return config;
});

app.config.globalProperties.$axios = axios
app.use(router)
app.use(pinia)
//使用plus
app.use(ElementPlus)
app.mount('#app')
